package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.Commdef;
import com.ktgj.flight.service.ICommdefService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 航信接口的航线Controller
 * 
 * @author ruoyi
 * @date 2021-08-30
 */
@ControllerAdvice
@RestController
@RequestMapping("/commdef")
public class CommdefController extends BaseController
{
    @Autowired
    private ICommdefService commdefService;

    /**
     * 查询航信接口的航线列表
     */
    @PreAuthorize(hasPermi = "flight:commdef:list")
    @GetMapping("/list")
    public TableDataInfo list(Commdef commdef)
    {
        startPage();
        List<Commdef> list = commdefService.selectCommdefList(commdef);
        return getDataTable(list);
    }

    /**
     * 导出航信接口的航线列表
     */
    @PreAuthorize(hasPermi = "flight:commdef:export")
    @Log(title = "航信接口的航线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Commdef commdef) throws IOException
    {
        List<Commdef> list = commdefService.selectCommdefList(commdef);
        ExcelUtil<Commdef> util = new ExcelUtil<Commdef>(Commdef.class);
        util.exportExcel(response, list, "航信接口的航线数据");
    }

    /**
     * 获取航信接口的航线详细信息
     */
    @PreAuthorize(hasPermi = "flight:commdef:query")
    @GetMapping(value = "/{commdefId}")
    public AjaxResult getInfo(@PathVariable("commdefId") Long commdefId)
    {
        return AjaxResult.success(commdefService.selectCommdefById(commdefId));
    }

    /**
     * 新增航信接口的航线
     */
    @PreAuthorize(hasPermi = "flight:commdef:add")
    @Log(title = "航信接口的航线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Commdef commdef)
    {
        return toAjax(commdefService.insertCommdef(commdef));
    }

    /**
     * 修改航信接口的航线
     */
    @PreAuthorize(hasPermi = "flight:commdef:edit")
    @Log(title = "航信接口的航线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Commdef commdef)
    {
        return toAjax(commdefService.updateCommdef(commdef));
    }

    /**
     * 删除航信接口的航线
     */
    @PreAuthorize(hasPermi = "flight:commdef:remove")
    @Log(title = "航信接口的航线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commdefIds}")
    public AjaxResult remove(@PathVariable Long[] commdefIds)
    {
        return toAjax(commdefService.deleteCommdefByIds(commdefIds));
    }
}
